/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.game.zone;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import java.util.LinkedList;
import java.util.List;
import log.Debug;

/**
 *
 * @author daz
 */
public class Response {

    public GameZoneExtension ext;

    public Response(GameZoneExtension ext) {
        this.ext = ext;
    }

    void sendListTable(List<Integer> numberPlayerInRooms, List<String> listUserNames, List<String> listRoomNames, String groupName, List<User> user) {
        ISFSObject resObj = new SFSObject();
        resObj.putUtfString(Flag.GROUP_NAME, groupName);
        resObj.putUtfStringArray(Flag.NAME_IN_ROOM, listUserNames);
        resObj.putIntArray(Flag.LIST_NUMBER_IN_Table, numberPlayerInRooms);
        resObj.putUtfStringArray(Flag.ROOM_NAME, listRoomNames);
        ext.send(Command.LIST_TABLE, resObj, user);
        log(resObj);
    }

    void sendListTable(List<Integer> levelMoney, int levelIndex, List<Integer> numberPlayerInRooms, List<String> listRoomNames, List<Long> listBet, String groupName, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt("level_index", levelIndex);
        resObj.putIntArray("list_level_money", levelMoney);
        resObj.putUtfString(Flag.GROUP_NAME, groupName);
        resObj.putIntArray(Flag.LIST_NUMBER_IN_Table, numberPlayerInRooms);
        resObj.putLongArray(Flag.ROOM_BET, listBet);
        resObj.putUtfStringArray(Flag.ROOM_NAME, listRoomNames);
        ext.send(Command.LIST_TABLE, resObj, user);
        log(resObj);
    }

    void sendTableInfo(String roomName, List<String> listNames, List<Integer> listPos, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putUtfString(Flag.ROOM_NAME, roomName);
        if (listNames != null) {
            resObj.putUtfStringArray(Flag.ROOM_PLAYER_NAME, listNames);
            resObj.putIntArray(Flag.ROOM_PLAYER_POS, listPos);
        } else {
            resObj.putUtfStringArray(Flag.ROOM_PLAYER_NAME, new LinkedList<String>());
            resObj.putIntArray(Flag.ROOM_PLAYER_POS, new LinkedList<Integer>());

        }
        ext.send(Command.TABLE_INFO, resObj, user);
        log(resObj);
    }

    public void sendNotEnough(User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt("enough_money", 0);
        ext.send(Command.BET_MONEY_INFO, resObj, user);
        log(resObj);
    }

    public void sendBetMoneyInfo(long userMoney, long moneyJoinMin, long moneyJoinMax, String roomName, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt("enough_money", 1);
        resObj.putLong("user_money", userMoney);
        resObj.putLong("money_min", moneyJoinMin);
        resObj.putLong("money_max", moneyJoinMax);
        resObj.putUtfString("room_name", roomName);
        ext.send(Command.BET_MONEY_INFO, resObj, user);
        log(resObj);
    }

    private void log(ISFSObject resObj) {
        if (Debug.isShowLog) {
            Debug.d(resObj.getDump());
        }
    }
}
